<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-default navbar-btn" href="${base}/platform/cardrack" data-pjax ><i class="ti-angle-left" id="goback"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="companyAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/cardrack/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">名称</label>

                            <div class="col-sm-8">
                                <input type="text" id="title" class="form-control" name="title" data-parsley-required="true" placeholder="名称">
                            </div>
                        </div>
                       
                        <div class="form-group">
                            <label for="state" class="col-sm-2 control-label">类型</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="rack_type" data-parsley-required="true" value="weixin" checked="checked" />微信
                                <!--  <input type="radio" name="rack_tpye" data-parsley-required="true" value="platform"  />平台 -->
                            </div>
                        </div>
                        <div class="form-group">
                        	<label for="img_url" class="col-sm-2 control-label">背景图</label>

                            <div class="col-sm-8">
                            	<div id="img_url_queue"></div>
                                <div>
                                	<input id="img_url_file_upload"  type="file" multiple="false">
                                </div>
                                <div id="img_url_img" style="padding: 5px;"></div>
                                <input type="hidden" id="img_url" name="img_url" value="" >
                           	</div>
                       	</div>
                        <div class="form-group">
                        	<label for="card_img_url" class="col-sm-2 control-label">卡券Logo</label>

                            <div class="col-sm-8">
                            	<div id="card_img_url_queue"></div>
                                <div>
                                	<input id="card_img_url_file_upload"  type="file" multiple="false">
                                </div>
                                <div id="card_img_url_img" style="padding: 5px;"></div>
                                <input type="hidden" id="card_img_url" name="card_img_url" value="" >
                           	</div>
                       	</div>
                        <div class="form-group">
                            <label for="state" class="col-sm-2 control-label">状态</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="state" data-parsley-required="true" value="0"  />启用
                                 <input type="radio" name="state" data-parsley-required="true" value="1"  />停用
                            </div>
                        </div>
                       	<div class="form-group">
                            <label for="card_list" class="col-sm-2 control-label">选择卡券</label>
							
                            <div class="col-sm-8">
                            	<%for(card in obj){%>
                               		<input type="checkbox" name="card_list" value="${card.rawid}">${card.title}</input>
                                <%}%>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">
	function img_url_clearFile() {
	    $("#img_url_img").html("");
	    $("#img_url_queue").html("");
	    $("#img_url").val("");
	}
	function card_img_url_clearFile() {
	    $("#card_img_url_img").html("");
	    $("#card_img_url_queue").html("");
	    $("#card_img_url").val("");
	}
    $(document).ready(function () {
    	$('#img_url_file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/*',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'img_url_queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img_url_img").html("<img src='${AppUploadRoot}" + data.data + "' style='width:150px;height:95px;'>");
                    $("#img_url").val(data.data);
                } else {
                	img_url_clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
            	img_url_clearFile();
            },
            'onClearQueue': function (queue) {
            	img_url_clearFile();
            },
            'onCancel': function () {
            	img_url_clearFile();
            }
        });
    	$('#card_img_url_file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/*',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'card_img_url_queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#card_img_url_img").html("<img src='${AppUploadRoot}" + data.data + "' style='width:150px;height:95px;'>");
                    $("#card_img_url").val(data.data);
                } else {
                	card_img_url_clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
            	card_img_url_clearFile();
            },
            'onClearQueue': function (queue) {
            	card_img_url_clearFile();
            },
            'onCancel': function () {
            	card_img_url_clearFile();
            }
        });
        $('#companyAddForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
            }
        });
    });
</script>
<%}%>